/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-07-21 08:59:12
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-07-21 14:06:18
 * @FilePath: \creation\5_creation\app\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios';

//抽离axios
const request = axios.create({
    timeout: 2000,
});

// Add a request interceptor
request.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
request.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    const status = error.response.status
    switch (status) {
        case '100':
            console.log('信息响应');
            break;
        case '200':
            console.log('成功响应');
            break;
        case '300':
            console.log('重定向消息');
            break;
        case '400':
            console.log('客户端错误响应');
            break;
        case '403':
            console.log('客户无权访问');
            break;
        case '404':
            console.log('找不到页面');
            break;
        case '500':
            console.log('服务器错误响应');
            break;
        default:
            break;
    }
    return Promise.reject(error);
});

export default request;